home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / SpeedLimitRuleDlg.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  5KB  |  175 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // SpeedLimitRuleDlg.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "resource.h"
  24. #include "SpeedLimitRuleDlg.h"
  25.  
  26. #if defined(_DEBUG) && !defined(MMGR)
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CSpeedLimitRuleDlg dialog
  34.  
  35.  
  36. CSpeedLimitRuleDlg::CSpeedLimitRuleDlg(CWnd* pParent /*=NULL*/)
  37.     : CDialog(CSpeedLimitRuleDlg::IDD, pParent)
  38. {
  39.     m_Day[ 0] = TRUE;
  40.     m_Day[ 1] = TRUE;
  41.     m_Day[ 2] = TRUE;
  42.     m_Day[ 3] = TRUE;
  43.     m_Day[ 4] = TRUE;
  44.     m_Day[ 5] = TRUE;
  45.     m_Day[ 6] = TRUE;
  46.     //{{AFX_DATA_INIT(CSpeedLimitRuleDlg)
  47.     m_DateCheck = FALSE;
  48.     m_Date = CTime::GetCurrentTime();
  49.     m_FromCheck = FALSE;
  50.     m_FromTime = CTime::GetCurrentTime();
  51.     m_ToCheck = FALSE;
  52.     m_ToTime = CTime::GetCurrentTime();
  53.     m_Speed = 8;
  54.     //}}AFX_DATA_INIT
  55. }
  56.  
  57.  
  58. void CSpeedLimitRuleDlg::DoDataExchange(CDataExchange* pDX)
  59. {
  60.     CDialog::DoDataExchange(pDX);
  61.     //{{AFX_DATA_MAP(CSpeedLimitRuleDlg)
  62.     DDX_Control(pDX, IDC_TO_TIME, m_ToCtrl);
  63.     DDX_Control(pDX, IDC_FROM_TIME, m_FromCtrl);
  64.     DDX_Control(pDX, IDC_DATE_VALUE, m_DateCtrl);
  65.     DDX_Check(pDX, IDC_DATE_CHECK, m_DateCheck);
  66.     DDX_DateTimeCtrl(pDX, IDC_DATE_VALUE, m_Date);
  67.     DDX_Check(pDX, IDC_FROM_CHECK, m_FromCheck);
  68.     DDX_DateTimeCtrl(pDX, IDC_FROM_TIME, m_FromTime);
  69.     DDX_Check(pDX, IDC_TO_CHECK, m_ToCheck);
  70.     DDX_DateTimeCtrl(pDX, IDC_TO_TIME, m_ToTime);
  71.     DDX_Text(pDX, IDC_SPEED, m_Speed);
  72.     DDV_MinMaxInt(pDX, m_Speed, 1, 1000000000);
  73.     //}}AFX_DATA_MAP
  74.     DDX_Check(pDX, IDC_CHECK_DAY1, m_Day[0]);
  75.     DDX_Check(pDX, IDC_CHECK_DAY2, m_Day[1]);
  76.     DDX_Check(pDX, IDC_CHECK_DAY3, m_Day[2]);
  77.     DDX_Check(pDX, IDC_CHECK_DAY4, m_Day[3]);
  78.     DDX_Check(pDX, IDC_CHECK_DAY5, m_Day[4]);
  79.     DDX_Check(pDX, IDC_CHECK_DAY6, m_Day[5]);
  80.     DDX_Check(pDX, IDC_CHECK_DAY7, m_Day[6]);
  81. }
  82.  
  83.  
  84. BEGIN_MESSAGE_MAP(CSpeedLimitRuleDlg, CDialog)
  85.     //{{AFX_MSG_MAP(CSpeedLimitRuleDlg)
  86.     ON_BN_CLICKED(IDC_DATE_CHECK, OnDateCheck)
  87.     ON_BN_CLICKED(IDC_TO_CHECK, OnToCheck)
  88.     ON_BN_CLICKED(IDC_FROM_CHECK, OnFromCheck)
  89.     //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CSpeedLimitRuleDlg message handlers
  94.  
  95. void CSpeedLimitRuleDlg::OnDateCheck() 
  96. {
  97.     // TODO: Add your control notification handler code here
  98.     UpdateData();
  99.  
  100.     m_DateCtrl.EnableWindow( m_DateCheck);
  101. }
  102.  
  103. void CSpeedLimitRuleDlg::OnToCheck() 
  104. {
  105.     // TODO: Add your control notification handler code here
  106.     UpdateData();
  107.  
  108.     m_ToCtrl.EnableWindow( m_ToCheck);
  109. }
  110.  
  111. void CSpeedLimitRuleDlg::OnFromCheck() 
  112. {
  113.     // TODO: Add your control notification handler code here
  114.     UpdateData();
  115.  
  116.     m_FromCtrl.EnableWindow( m_FromCheck);
  117. }
  118.  
  119. BOOL CSpeedLimitRuleDlg::OnInitDialog() 
  120. {
  121.     CDialog::OnInitDialog();
  122.     
  123.     // TODO: Add extra initialization here
  124.     m_DateCtrl.EnableWindow( m_DateCheck);
  125.     m_ToCtrl.EnableWindow( m_ToCheck);
  126.     m_FromCtrl.EnableWindow( m_FromCheck);
  127.  
  128.     return TRUE;  // return TRUE unless you set the focus to a control
  129.                   // EXCEPTION: OCX Property Pages should return FALSE
  130. }
  131.  
  132. CSpeedLimit CSpeedLimitRuleDlg::GetSpeedLimit()
  133. {
  134.     CSpeedLimit res;
  135.     
  136.     res.m_DateCheck = m_DateCheck;
  137.     res.m_Date.y = m_Date.GetYear();
  138.     res.m_Date.m = m_Date.GetMonth();
  139.     res.m_Date.d = m_Date.GetDay();
  140.     res.m_FromCheck = m_FromCheck;
  141.     res.m_ToCheck = m_ToCheck;
  142.     res.m_FromTime.h = m_FromTime.GetHour();
  143.     res.m_FromTime.m = m_FromTime.GetMinute();
  144.     res.m_FromTime.s = m_FromTime.GetSecond();
  145.     res.m_ToTime.h = m_ToTime.GetHour();
  146.     res.m_ToTime.m = m_ToTime.GetMinute();
  147.     res.m_ToTime.s = m_ToTime.GetSecond();
  148.     res.m_Speed = m_Speed;
  149.  
  150.     res.m_Day = 0;
  151.     for (int i = 0; i < 7; i++)
  152.         if (m_Day[i])
  153.             res.m_Day |= 1 << i;
  154.  
  155.     return res;
  156. }
  157.  
  158. void CSpeedLimitRuleDlg::FillFromSpeedLimit(const CSpeedLimit &sl)
  159. {
  160.     m_DateCheck = sl.m_DateCheck;
  161.     if (m_DateCheck)
  162.         m_Date = CTime(sl.m_Date.y, sl.m_Date.m, sl.m_Date.d, 0, 0, 0);
  163.     m_FromCheck = sl.m_FromCheck;
  164.     if (m_FromCheck)
  165.         m_FromTime = CTime(2011, 1, 1, sl.m_FromTime.h, sl.m_FromTime.m, sl.m_FromTime.s);
  166.     m_ToCheck = sl.m_ToCheck;
  167.     if (m_ToCheck)
  168.         m_ToTime = CTime(2011, 1, 1, sl.m_ToTime.h, sl.m_ToTime.m, sl.m_ToTime.s);;
  169.     m_Speed = sl.m_Speed;
  170.  
  171.     for (int i = 0; i < 7; i++)
  172.         m_Day[i] = (sl.m_Day >> i) % 2;
  173. }
  174.  
  175.